常用命令
删除
1 2
| docker rm container_id docker rmi image_id
|
docker停止、移除所有
1 2
| docker stop * docker rm *
|
docker 查看日志
1
| docker logs mydata_mall-admin_1
|
创建容器并运行
1
| docker run -p 80:80 --name nginx -it nginx bash
|
复制文件
1 2
| docker cp /opt/test.js tomcat:/usr/local/tomcat/webapps/test/js docker cp tomcat:/usr/local/tomcat/webapps/test/js /opt/test.js
|
出现registry-1.docker.io/v2地址超时
换用国内的daocloud仓库:
bash vi /etc/docker/daemon.json
1 2 3
| { "registry-mirrors": ["https://registry.docker-cn.com"] }
|
systemctl restart docker
redis安装
- 下载镜像文件
docker pull redis:3.2
- 创建实例并启动
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -d redis:3.2 redis-server --appendonly yes
- 使用redis镜像执行redis-cli命令连接
docker exec -it redis redis-cli
。
exec表示执行,-i表示即使没有附加也保持STDIN打开,-t表示分配一个伪终端 redis为镜像名字 redis-cli为启动redis客户端命令工具
nginx安装
1 2 3 4 5 6 7
| docker pull nginx:1.10 docker run -p 80:80 --name nginx -it nginx bash docker cp nginx:/etc/nginx/ /mydata/nginx/conf docker ps -a docker stop container_id docker rm container_id docker run -p 80:80 --name nginx -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/logs:/var/log/nginx -v /mydata/nginx/conf:/etc/nginx -d nginx:1.10
|
rabbitmq安装
1 2
| docker pull rabbitmq:management docker run -d --name rabbitmq --publish 5671:5671 --publish 5672:5672 --publish 4369:4369 --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 rabbitmq:management
|
elasticsearch安装
1 2 3 4
| docker pull elasticsearch:2.4 docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data -d elasticsearch:2.4
curl http://192.168.1.10:9200/
|
安装插件
1 2 3 4 5 6 7 8 9
| docker exec -it elasticsearch bash
plugin install mobz/elasticsearch-head
curl http://192.168.1.10:9200/_plugin/head/
plugin install lmenezes/elasticsearch-kopf
curl http://192.168.1.10:9200/_plugin/kopf/
|
安装分词器
下载:https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v5.6.4
1 2 3 4 5
| tar -xvf elasticsearch-analysis-ik-1.10.6.tar.gz docker cp elasticsearch-analysis-ik-1.10.6 elasticsearch:/usr/share/elasticsearch/plugins docker restart elasticsearch
curl -H "Content-Type:application/json" -X POST --data '{"analyzer":"ik","text":"联想是全球最大的笔记本厂商"}' http://192.168.0.10:9200/_analyze
|
mongodb安装
1 2 3
| docker pull mongo:3.2 docker run -p 27017:27017 --name mongo -v /mydata/mongo/db:/data/db -d mongo:3.2 docker exec -it mongo mongo
|
Docker Registry2.0搭建
1 2 3 4 5
| docker run -d -p 5000:5000 --restart=always --name registry2 registry:2
docker push localhost:5000/macro/eureka-server:0.0.1
docker tag macro/eureka-server:0.0.1 localhost:5000/macro/eureka-server:0.0.1
|
使用maven构建Docker镜像
构建镜像
command:mvn clean package docker:build
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| vi /usr/lib/systemd/system/docker.service
ExecStart= ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
systemctl daemon-reload
systemctl restart docker
ps -ef|grep docker
telnet 192.168.0.10 2375
|
推送镜像到私有仓库
command:
1
| mvn clean package docker:build -DpushImage
|
tip:
1 2 3 4 5 6
| <imageName>192.168.0.10:5000/macro/${project.artifactId}:${project.version}</imageName>
echo '{ "insecure-registries":["192.168.0.10:5000"] }' >> /etc/docker/daemon.json
curl -XGE Thttp://192.168.0.10:5000/v2/_catalog
|
修改Docker镜像存放位置
1 2 3 4 5 6 7 8
| docker info | grep "Docker Root Dir"(默认为/var/lib/docker)
systemctl stop docker
mv /var/lib/docker /root/data/docker
ln -s /root/data/docker /var/lib/docker
|
SpringBoot应用自动化部署
1 2 3 4 5 6 7 8 9 10
| docker-compose -f docker-compose.yml up -d
docker-compose ps
docker-compose remove
docker-compose stop
docker-compose restart
|
参考: